package items;

import java.util.ArrayList;

/*
 * Consolidate separate item categories
 */
public class Category {
	private String category;
	private ArrayList<String> itemNameList;
	private ArrayList<String> itemNumberList;
	
	public Category(String category) {
		this.category = category;
		this.pickCategory();
	}

	public String getCategory() {
		return this.category;
	}
	
	public ArrayList<String> getItemNameList() {
		return this.itemNameList;
	}
	
	public ArrayList<String> getItemNumberList() {
		return this.itemNumberList;
	}
	
	private void pickCategory() {
		shortInput(category);
		Number categoryNumber = Integer.parseInt(category);
		
		switch (categoryNumber.intValue()) {
			case 1:
				category = Barrows.group;
				itemNameList = Barrows.itemNameList();
				itemNumberList = Barrows.itemNumberList();
				break;
			case 2:
				category = Bars.group;
				itemNameList = Bars.itemNameList();
				itemNumberList = Bars.itemNumberList();
				break;
			case 3:
				category = Ores.group;
				itemNameList = Ores.itemNameList();
				itemNumberList = Ores.itemNumberList();
				break;
			case 4:
				category = Rares.group;
				itemNameList = Rares.itemNameList();
				itemNumberList = Rares.itemNumberList();
				break;
			case 5:
				category = Runes.group;
				itemNameList = Runes.itemNameList();
				itemNumberList = Runes.itemNumberList();
				break;
			case 6:
				category = Others.group;
				itemNameList = Others.itemNameList();
				itemNumberList = Others.itemNumberList();
				break;
			default:
				System.out.println("item not found: " + categoryToNumber(category));
				System.exit(0);
		}
	}
	
	private String categoryToNumber(String category) {
		if(Barrows.itemCategory(category)) return "1";
		if(Bars.itemCategory(category)) return "2";
		if(Ores.itemCategory(category)) return "3";
		if(Rares.itemCategory(category)) return "4";
		if(Runes.itemCategory(category)) return "5";
		if(Others.itemCategory(category)) return "6";
		return "0";
	}
	
	private String numberToCategory(Number number) {
		switch (number.intValue()) {
			case 1: return Barrows.group;
			case 2: return Bars.group;
			case 3: return Ores.group;
			case 4: return Rares.group;
			case 5: return Runes.group;
			case 6: return Others.group;
			default: return "not-found";
		}
	}

	private String shortInput(String category) {
		Number number;
		try {
			number = Integer.parseInt(category);
		}
		catch (NumberFormatException e) {
			return categoryToNumber(category);
		}
		String numberToCategory = numberToCategory(number);
		return numberToCategory;
	}
	
	public String shortNameConvert(String category) {
		return shortInput(category);
	}
}
